package com.iqiyi.pps.epg.web;

import com.iqiyi.pps.epg.core.model.statistic.StatisticOcrData;
import com.iqiyi.pps.epg.core.model.statistic.StatisticSty2Data;
import com.iqiyi.pps.epg.core.service.statistic.StatisticOcrDataServiceImpl;
import com.iqiyi.pps.epg.core.service.statistic.StatisticSty2DataServiceImpl;
import com.iqiyi.pps.epg.core.utils.DateTimeUtil;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.Timestamp;
import java.util.Calendar;

/**
 * Created by zhang on 2016/5/4.
 */
public class TestMainSaveData {

    public static void saveOcr() {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                new String[]{"spring/ApplicationContext.xml"});
        StatisticOcrDataServiceImpl server = context.getBean(StatisticOcrDataServiceImpl.class);
        for (int i = 0; i < 10000; i++) {
            int random = -(int) (Math.random() * 7);
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, random);
            StatisticOcrData ocr = new StatisticOcrData();
            ocr.setChannelId("ChannelId");
            ocr.setChannelName("ChannelName");
            ocr.setProgramId("ProgramId");
            ocr.setProgramName("ProgramName");
            ocr.setCategoryName("CategoryName");
            ocr.setOcrReturnTitle("Title");
            ocr.setUserSubmitTitle("Title");
            ocr.setSame(true);
            ocr.setUser("张璟");
            ocr.setStatisticTime(new Timestamp(calendar.getTimeInMillis()));
            server.save(ocr);
        }
    }

    public static void saveSty2() {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                new String[]{"spring/ApplicationContext.xml"});
        StatisticSty2DataServiceImpl service = context.getBean(StatisticSty2DataServiceImpl.class);
        int times = 1;
        int num = 1;
        while (num >= 50000 && times >= 3) {
            Calendar calendar = Calendar.getInstance();
            if (num >= 50000) {
                num = 1;
                switch (times) {
                    case 1:
                        calendar.set(Calendar.MONTH, 5);
                        calendar.set(Calendar.DATE, 4);
                        break;
                    case 2:
                        calendar.set(Calendar.MONTH, 5);
                        calendar.set(Calendar.DATE, 2);
                        break;
                    case 3:
                        calendar.set(Calendar.MONTH, 4);
                        calendar.set(Calendar.DATE, 28);
                }
            }
            StatisticSty2Data data = new StatisticSty2Data();
            data.setChannelId("1");
            data.setChannelName("ChannelName");
            data.setChannelCode("ChannelCode");
            data.setProgramId("101");
            data.setProgramName("ProgramName");
            data.setCategoryName("CategoryName");
            data.setAlbumName("AlbumName");
            data.setProgramTime(121);
            data.setUser("张秀秀");
            data.setStatisticTime(new Timestamp(calendar.getTimeInMillis()));
            data.setHeaderCompleteNumbers(0);
            data.setHeaderIncompleteNumbers(1);
            data.setHeaderFaultNumbers(0);
            data.setLastCompleteNumbers(1);
            data.setLastIncompleteNumbers(0);
            data.setLastFaultNumbers(0);
            data.setAdCompleteNumbers(0);
            data.setAdIncompleteNumbers(0);
            data.setAdFaultNumbers(1);
            service.save(data);
            num ++;
        }
    }

    public static void main(String[] args) {
        ApplicationContext context = new ClassPathXmlApplicationContext(
                new String[]{"spring/ApplicationContext.xml"});
        StatisticSty2DataServiceImpl service = context.getBean(StatisticSty2DataServiceImpl.class);
        int times = 1;
        int num = 1;
        Calendar calendar = Calendar.getInstance();
        while (num <= 50000 && times <= 3) {
            if (num == 50000) {
                num = 1;
                times++;
            }
            if (num == 1) {
                switch (times) {
                    case 1:
                        calendar.set(Calendar.DAY_OF_MONTH, 4);  //设置日期
                        break;
                    case 2:
                        calendar.set(Calendar.DAY_OF_MONTH, 2);  //设置日期
                        break;
                    case 3:
                        calendar.set(Calendar.DAY_OF_MONTH, 28);  //设置日期
                        calendar.set(Calendar.MONTH, 3);  //设置日期
                }

            }
            StatisticSty2Data data = new StatisticSty2Data();
            data.setChannelId("1");
            data.setChannelName("ChannelName");
            data.setChannelCode("ChannelCode");
            data.setProgramId("101");
            data.setProgramName("ProgramName");
            data.setCategoryName("CategoryName");
            data.setAlbumName("AlbumName");
            data.setProgramTime(121);
            data.setUser("张秀秀");
            data.setStatisticTime(new Timestamp(calendar.getTimeInMillis()));
            data.setHeaderCompleteNumbers(0);
            data.setHeaderIncompleteNumbers(1);
            data.setHeaderFaultNumbers(0);
            data.setLastCompleteNumbers(1);
            data.setLastIncompleteNumbers(0);
            data.setLastFaultNumbers(0);
            data.setAdCompleteNumbers(0);
            data.setAdIncompleteNumbers(0);
            data.setAdFaultNumbers(1);
            service.save(data);
            num ++;

            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
